home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / System / XFD / Developer / Sources / ASM / Switch.a < prev    next >
Encoding:
Text File  |  2001-09-16  |  10.7 KB  |  552 lines

  1. **********************************************************
  2. **       XFD external decruncher for Switch files       **
  3. **       written and © 1998 by Codetapper/Action!       **
  4. **                                                      **
  5. **   This decrunches old files crunched by the group    **
  6. **    Switch who trained many games around 1990. The    **
  7. **  cruncher they seemed to use most of the time is a   **
  8. **     standard address type, and this program will     **
  9. **         decrunch the 2 versions I have seen.         **
  10. **                                                      **
  11. **          Contact me: codetapper@hotmail.com          **
  12. **      Visit the Action HQ: http://zap.to/action/      **
  13. **                                                      **
  14. **           Greetings to all Action members:           **
  15. **        Tachyon, Elp, Legionary, DJ DeCreator,        **
  16. **                  Hoju, and Shastar!                  **
  17. **********************************************************
  18.  
  19.  
  20. SwitchMinLen    equ    $156        ;Min. file length for header and data
  21.  
  22.         SECTION    SWITCH,CODE
  23.  
  24.         INCLUDE    AINCLUDE:IncDirs.i    ;change this as you need it
  25.         INCLUDE    "libraries/xfdmaster.i"
  26.  
  27. ; xfdForeman structure MUST be first thing in all external decrunchers
  28.  
  29. F_XPK        moveq    #-1,d0        ;security
  30.         rts
  31.         dc.l    XFDF_ID        ;id
  32.         dc.w    1        ;version
  33.         dc.w    0
  34.         dc.l    0,0        ;private
  35.         dc.l    S_Switch    ;first slave
  36.  
  37.         dc.b    "$VER: Switch 1.3 (25.07.1999) by Codetapper/Action!",13,10,0
  38.         cnop    0,4
  39.  
  40. **************************************************
  41.  
  42. ; xfdSlave structure: this one doesn't support segment decrunching
  43.  
  44. S_Switch    dc.l    S_SwitchAlt    ;next slave
  45.         dc.w    2        ;version
  46.         dc.w    36        ;master version
  47.         dc.l    N_Switch    ;name
  48.         dc.w    XFDPFF_ADDR    ;flags
  49.         dc.w    0
  50.         dc.l    RB_Switch    ;recog buffer
  51.         dc.l    DB_Switch    ;decrunch buffer
  52.         dc.l    0        ;recog segment
  53.         dc.l    0        ;decrunch segment
  54.         dc.w    0,0        ;slave/replace id
  55.         dc.l    SwitchMinLen    ;min. file length for header and data
  56.  
  57. N_Switch    dc.b    'Switch Cruncher',0
  58.         even
  59.  
  60. ;---------------------------------------------------------
  61. ; Recog buffer function: receives buffer + length in a0/d0
  62. ;---------------------------------------------------------
  63. RB_Switch    cmp.l    #$41fa0134,(a0)        ;lea $136(pc),a0
  64.         bne.s    .Exit
  65.         cmp.w    #$d1fc,4(a0)        ;add.l    #xxxxxxxx,a0
  66.         bne.s    .Exit
  67.         cmp.w    #$43f9,10(a0)        ;lea    xxxxx,a1
  68.         bne.s    .Exit
  69.         cmp.l    #$2460d5c9,$10(a0)    ;move.l    -(a0),a2
  70.                         ;add.l    a1,a2
  71.         bne.s    .Exit
  72.         cmp.l    #$20207203,$14(a0)    ;move.l    -(a0),d0
  73.                         ;moveq    #3,d1
  74.         bne.s    .Exit
  75.         cmp.l    #$610000fc,$18(a0)    ;bsr    Dec18    ;Start+$116
  76.         bne.s    .Exit
  77.         cmp.l    #$53414282,$116(a0)    ;subq.w    #1,d1
  78.                         ;clr.l    d2
  79.         bne.s    .Exit
  80.         cmp.l    #$51c9ffe8,$130(a0)    ;dbra    d1,Dec19
  81.         bne.s    .Exit
  82.         cmp.w    #$4e75,$134(a0)    ;rts
  83.         bne.s    .Exit
  84.         moveq    #1,d0
  85.         rts
  86.  
  87. .Exit        moveq    #0,d0
  88.         rts
  89.  
  90. ;---------------------------------------------------------
  91. ; Decrunch buffer function: receives bufferinfo in a0
  92. ;---------------------------------------------------------
  93. DB_Switch    movem.l    d2-d7/a2-a6,-(a7)
  94.         move.l    a0,a5
  95.         move.l    xfdbi_SourceBuffer(a5),a2
  96.  
  97. ; first of all, we calculate the length of the decrunched file
  98.  
  99.         move.l    6(a2),d0    ; a2 = source
  100.         add.l    d0,a2
  101.         move.l    #$136,d0
  102.         add.l    d0,a2
  103.         move.l    -(a2),d0
  104.  
  105. ; now we have the desired length and allocate the buffer
  106.  
  107.         move.l    d0,xfdbi_TargetBufSaveLen(a5)
  108.         move.l    d0,xfdbi_TargetBufLen(a5)
  109.  
  110.         move.l    xfdbi_SourceBuffer(a5),a2
  111.         move.l    12(a2),xfdbi_DecrAddress(a5);
  112.         move.l    $108(a2),xfdbi_JmpAddress(a5);
  113.  
  114.         move.l    xfdbi_TargetBufMemType(a5),d1
  115.         move.l    4.w,a6
  116.         jsr    -198(a6)
  117.         move.w    #XFDERR_NOMEMORY,xfdbi_Error(a5)
  118.         move.l    d0,xfdbi_TargetBuffer(a5)
  119.         beq.b    .Exit
  120.  
  121. ; let's fill the buffer
  122.  
  123.         move.l    d0,a1
  124.         move.l    xfdbi_SourceBuffer(a5),a0
  125.         bsr.b    D_Switch
  126.  
  127. ; successful exit
  128.  
  129.         moveq    #1,d0
  130. .Exit        movem.l    (a7)+,d2-d7/a2-a6
  131.         rts
  132.  
  133. ;---------------------------------------------------------
  134. ; Switch decruncher (ripped from Puzznic, Helter Skelter
  135. ; and Rush Hour from Switch Game Pack 12)
  136. ;
  137. ; Inputs:
  138. ; a0 = Source data (originally)
  139. ; a1 = Destination address (added by Codetapper!)
  140. ;
  141. ; Returns:
  142. ; None
  143. ;---------------------------------------------------------
  144. D_Switch
  145.     move.l    6(a0),d0    ; a0 = source, a1 = dest
  146.     add.l    d0,a0
  147.     move.l    #$136,d0
  148.     add.l    d0,a0
  149.     move.l    -(a0),a2
  150.     add.l    a1,a2
  151.     move.l    -(a0),d0
  152. Dec1    moveq    #3,d1
  153.     bsr    Dec18
  154.     tst.b    d2
  155.     beq.s    Dec8
  156.     cmp.w    #7,d2
  157.     bne.s    Dec4
  158.     lsr.l    #1,d0
  159.     bne.s    Dec2
  160.     bsr    Read32bits
  161. Dec2    bcc.s    Dec3
  162.     moveq    #10,d1
  163.     bsr    Dec18
  164.     tst.w    d2
  165.     bne.s    Dec4
  166.     moveq    #$12,d1
  167.     bsr    Dec18
  168.     bra.s    Dec4
  169.  
  170. Dec3    moveq    #4,d1
  171.     bsr    Dec18
  172.     addq.w    #7,d2
  173. Dec4    subq.w    #1,d2
  174. Dec5    moveq    #7,d1
  175. Dec6    lsr.l    #1,d0
  176.     beq.s    Dec7
  177.     roxl.l    #1,d3
  178.     dbra    d1,Dec6
  179.  
  180.     move.b    d3,-(a2)
  181. ;    move.b    d3,$dff180        ; In (Alt) version only!
  182.     dbra    d2,Dec5
  183.  
  184.     bra.s    Dec8
  185.  
  186. Dec7    move.l    -(a0),d0
  187. ;    move.w    d0,$DFF180        ; In normal version only!
  188.     move    #$10,CCR
  189.     roxr.l    #1,d0
  190.     roxl.l    #1,d3
  191.     dbra    d1,Dec6
  192.  
  193.     move.b    d3,-(a2)
  194.     dbra    d2,Dec5
  195.  
  196. Dec8    cmp.l    a2,a1
  197.     bge.b    StartGame
  198.     moveq    #2,d1
  199.     bsr    Dec18
  200.     moveq    #2,d3
  201.     moveq    #8,d1
  202.     tst.w    d2
  203.     beq.s    Dec16
  204.     moveq    #4,d3
  205.     cmp.w    #2,d2
  206.     beq.b    Dec13
  207.     moveq    #3,d3
  208.     cmp.w    #1,d2
  209.     beq.b    Dec11
  210.     moveq    #2,d1
  211.     bsr.b    Dec18
  212.     cmp.w    #3,d2
  213.     beq.s    Dec10
  214.     cmp.w    #2,d2
  215.     beq.s    Dec9
  216.     addq.w    #5,d2
  217.     move.w    d2,d3
  218.     bra.b    Dec13
  219.  
  220. Dec9    moveq    #2,d1
  221.     bsr.s    Dec18
  222.     addq.w    #7,d2
  223.     move.w    d2,d3
  224.     bra.b    Dec13
  225.  
  226. Dec10    moveq    #8,d1
  227.     bsr.s    Dec18
  228.     move.w    d2,d3
  229.     bra.b    Dec13
  230.  
  231. Dec11    moveq    #8,d1
  232.     lsr.l    #1,d0
  233.     bne.s    Dec12
  234.     bsr.s    Read32bits
  235. Dec12    bcs.s    Dec16
  236.     moveq    #14,d1
  237.     bra.s    Dec16
  238.  
  239. Dec13    moveq    #$10,d1
  240.     lsr.l    #1,d0
  241.     bne.s    Dec14
  242.     bsr.s    Read32bits
  243. Dec14    bcc.s    Dec16
  244.     moveq    #8,d1
  245.     lsr.l    #1,d0
  246.     bne.s    Dec15
  247.     bsr.s    Read32bits
  248. Dec15    bcs.s    Dec16
  249.     moveq    #12,d1
  250. Dec16    bsr.s    Dec18
  251.     subq.w    #1,d3
  252. Dec17    move.b    -1(a2,d2.l),-(a2)
  253.     dbra    d3,Dec17
  254.  
  255.     bra    Dec1
  256.  
  257. StartGame    rts    ;jmp    $71000
  258.  
  259. Read32bits    move.l    -(a0),d0
  260.     move    #$10,CCR
  261.     roxr.l    #1,d0
  262.     rts
  263.  
  264. Dec18    subq.w    #1,d1
  265.     clr.l    d2
  266. Dec19    lsr.l    #1,d0
  267.     beq.s    Dec20
  268.     roxl.l    #1,d2
  269.     dbra    d1,Dec19
  270.  
  271.     rts
  272.  
  273. Dec20    move.l    -(a0),d0
  274.     move    #$10,CCR
  275.     roxr.l    #1,d0
  276.     roxl.l    #1,d2
  277.     dbra    d1,Dec19
  278.  
  279.     rts
  280.  
  281.     even
  282.  
  283. ;---------------------------------------------------------
  284. ; Switch alternate decruncher (ripped from Sword and the
  285. ; Rose and Scrabble from Switch Game Pack 12)
  286. ;
  287. ; Inputs:
  288. ; a0 = Source data (originally)
  289. ; a1 = Destination address (added by Codetapper!)
  290. ;
  291. ; Returns:
  292. ; None
  293. ;---------------------------------------------------------
  294. D_SwitchAlt
  295.     ;lea    SwitchAltData(pc),a3
  296.     move.l    a0,a3        ; Codetapper
  297.     add.w    2(a0),a3        ; modified
  298.     addq.w    #2,a3        ; this!
  299.  
  300.     move.l    a3,d0
  301.     move.l    8(a3),d1    ; d1 = Length of crunched data
  302.     ;lea    ActualAltData(pc),a0
  303.     move.l    a0,a4        ; Codetapper
  304.     add.w    $c(a0),a4        ; modified
  305.     add.w    #$c,a4        ; this
  306.     move.l    a4,a0        ; bit!
  307.  
  308.     add.l    d1,a0        ; a0 = End of crunched data
  309.     ;move.l    4(a3),a1        ; a1 already points to destination
  310.     move.l    -(a0),a2
  311.     add.l    a1,a2
  312.     move.l    -(a0),d0
  313. .Dec1    moveq    #3,d1
  314.     bsr    .Dec19
  315.     tst.b    d2
  316.     beq.s    .Dec8
  317.     cmp.w    #7,d2
  318.     bne.s    .Dec4
  319.     lsr.l    #1,d0
  320.     bne.s    .Dec2
  321.     bsr    .Read32bits
  322. .Dec2    bcc.b    .Dec3
  323.     moveq    #10,d1
  324.     bsr    .Dec19
  325.     tst.w    d2
  326.     bne.s    .Dec4
  327.     moveq    #$12,d1
  328.     bsr    .Dec19
  329.     bra.s    .Dec4
  330.  
  331. .Dec3    moveq    #4,d1
  332.     bsr    .Dec19
  333.     addq.w    #7,d2
  334. .Dec4    subq.w    #1,d2
  335. .Dec5    moveq    #7,d1
  336. .Dec6    lsr.l    #1,d0
  337.     beq.b    .Dec7
  338.     roxl.l    #1,d3
  339.     dbra    d1,.Dec6
  340.  
  341.     move.b    d3,-(a2)
  342.     ;move.b    d3,$DFF180
  343.     dbra    d2,.Dec5
  344.  
  345.     bra.s    .Dec8
  346.  
  347. .Dec7    move.l    -(a0),d0
  348.     move    #$10,CCR
  349.     roxr.l    #1,d0
  350.     roxl.l    #1,d3
  351.     dbra    d1,.Dec6
  352.  
  353.     move.b    d3,-(a2)
  354.     dbra    d2,.Dec5
  355.  
  356. .Dec8    cmp.l    a2,a1
  357.     bge.b    .StartGame
  358.     moveq    #2,d1
  359.     bsr    .Dec19
  360.     moveq    #2,d3
  361.     moveq    #8,d1
  362.     tst.w    d2
  363.     beq.s    .Dec16
  364.     moveq    #4,d3
  365.     cmp.w    #2,d2
  366.     beq.s    .Dec13
  367.     moveq    #3,d3
  368.     cmp.w    #1,d2
  369.     beq.s    .Dec11
  370.     moveq    #2,d1
  371.     bsr.b    .Dec19
  372.     cmp.w    #3,d2
  373.     beq.s    .Dec10
  374.     cmp.w    #2,d2
  375.     beq.s    .Dec9
  376.     addq.w    #5,d2
  377.     move.w    d2,d3
  378.     bra.s    .Dec13
  379.  
  380. .Dec9    moveq    #2,d1
  381.     bsr.s    .Dec19
  382.     addq.w    #7,d2
  383.     move.w    d2,d3
  384.     bra.s    .Dec13
  385.  
  386. .Dec10    moveq    #8,d1
  387.     bsr.s    .Dec19
  388.     move.w    d2,d3
  389.     bra.s    .Dec13
  390.  
  391. .Dec11    moveq    #8,d1
  392.     lsr.l    #1,d0
  393.     bne.s    .Dec12
  394.     bsr.s    .Read32bits
  395. .Dec12    bcs.s    .Dec16
  396.     moveq    #14,d1
  397.     bra.s    .Dec16
  398.  
  399. .Dec13    moveq    #$10,d1
  400.     lsr.l    #1,d0
  401.     bne.s    .Dec14
  402.     bsr.s    .Read32bits
  403. .Dec14    bcc.s    .Dec16
  404.     moveq    #8,d1
  405.     lsr.l    #1,d0
  406.     bne.s    .Dec15
  407.     bsr.s    .Read32bits
  408. .Dec15    bcs.s    .Dec16
  409.     moveq    #12,d1
  410. .Dec16    bsr.s    .Dec19
  411.     subq.w    #1,d3
  412. .Dec17    move.b    -1(a2,d2.l),-(a2)
  413.     dbra    d3,.Dec17
  414.  
  415.     bra    .Dec1
  416.  
  417. .StartGame    rts    ;jmp    $75000
  418.  
  419. .Read32bits    move.l    -(a0),d0
  420.     move    #$10,CCR
  421.     roxr.l    #1,d0
  422.     rts
  423.  
  424. .Dec18    move.l    -(a0),d0
  425.     move    #$10,CCR
  426.     roxr.l    #1,d0
  427.     roxl.l    #1,d2
  428.     dbra    d1,.Dec20
  429.  
  430.     rts
  431.  
  432. .Dec19    subq.w    #1,d1
  433.     clr.l    d2
  434. .Dec20    lsr.l    #1,d0
  435.     beq.s    .Dec18
  436.     roxl.l    #1,d2
  437.     dbra    d1,.Dec20
  438.  
  439.     rts
  440.  
  441. ;SwitchAltData
  442. ;    dc.l    $40624
  443. ;    dc.l    $20000
  444. ;    dc.l    $2EAD4
  445. ;ActualAltData
  446. ;    dc.l    $61BE4FF
  447. ;    dc.l    $E599A04E
  448. ;    dc.l    $51571861
  449.  
  450. *****************
  451.  
  452. S_SwitchAlt
  453.     dc.l    0        ;next slave
  454.     dc.w    2        ;version
  455.     dc.w    36        ;master version
  456.     dc.l    N_SwitchAlt    ;name
  457.     dc.w    XFDPFF_ADDR    ;flags
  458.     dc.w    0
  459.     dc.l    RB_SwitchAlt    ;recog buffer
  460.     dc.l    DB_SwitchAlt    ;decrunch buffer
  461.     dc.l    0        ;recog segment
  462.     dc.l    0        ;decrunch segment
  463.     dc.w    0,0        ;slave/replace id
  464.     dc.l    SwitchMinLen    ;min. file length for header and data
  465.  
  466. N_SwitchAlt
  467.     dc.b    'Switch Cruncher Alternate',0
  468.     even
  469.  
  470. ;---------------------------------------------------------
  471. ; Recog buffer function: receives buffer + length in a0/d0
  472. ;---------------------------------------------------------
  473. RB_SwitchAlt    cmp.l    #$47fa0132,(a0)        ;lea    $134(pc),a3
  474.         bne.s    .Exit
  475.         cmp.l    #$200b222b,4(a0)    ;move.l    a3,d0
  476.                         ;move.l    8(a3),d1
  477.         bne.s    .Exit
  478.         cmp.l    #$841fa,8(a0)        ;lea    $140(pc),a0
  479.         bne.s    .Exit
  480.         cmp.l    #$0134d1c1,12(a0)    ;add.l    d1,a0
  481.         bne.s    .Exit
  482.         cmp.l    #$226b0004,$10(a0)    ;move.l    4(a3),a1
  483.         bne.s    .Exit
  484.         cmp.l    #$2460d5c9,$14(a0)    ;move.l    -(a0),a2
  485.                         ;add.l    a1,a2
  486.         bne.s    .Exit
  487.         cmp.l    #$61000106,$1c(a0)    ;bsr    Dec18    ;Start+$124
  488.         bne.s    .Exit
  489.         cmp.l    #$53414282,$124(a0)    ;subq.w    #1,d1
  490.                         ;clr.l    d2
  491.         bne.s    .Exit
  492.         cmp.l    #$51c9fff8,$12e(a0)    ;dbra    d1,Dec19
  493.         bne.s    .Exit
  494.         cmp.w    #$4e75,$132(a0)        ;rts
  495.         bne.s    .Exit
  496.         moveq    #1,d0
  497.         rts
  498.  
  499. .Exit        moveq    #0,d0
  500.         rts
  501.  
  502. ;---------------------------------------------------------
  503. ; Decrunch buffer function: receives bufferinfo in a0
  504. ;---------------------------------------------------------
  505. DB_SwitchAlt    movem.l    d2-d7/a2-a6,-(a7)
  506.         move.l    a0,a5
  507.         move.l    xfdbi_SourceBuffer(a5),a2
  508.  
  509. ; first of all, we calculate the length of the decrunched file
  510.  
  511.         move.l    a2,a3
  512.         add.w    2(a2),a3
  513.         addq.w    #2,a3        ; a3 = Pointer to load/jump/length
  514.  
  515.         move.l    8(a3),d1    ; d1 = Length of crunched data
  516.  
  517.         move.l    a3,a4
  518.         addq    #8,a4
  519.         add.l    d1,a4
  520.         move.l    (a4),d0        ; d0 = Length of decrunched data
  521.  
  522. ; now we have the desired length and allocate the buffer
  523.  
  524.         move.l    d0,xfdbi_TargetBufSaveLen(a5)
  525.         move.l    d0,xfdbi_TargetBufLen(a5)
  526.  
  527.         move.l    xfdbi_SourceBuffer(a5),a2
  528.         move.l    4(a3),xfdbi_DecrAddress(a5);
  529.         move.l    $106(a2),xfdbi_JmpAddress(a5);
  530.  
  531.         move.l    xfdbi_TargetBufLen(a5),d0
  532.         move.l    xfdbi_TargetBufMemType(a5),d1
  533.         move.l    4.w,a6
  534.         jsr    -198(a6)
  535.         move.w    #XFDERR_NOMEMORY,xfdbi_Error(a5)
  536.         move.l    d0,xfdbi_TargetBuffer(a5)
  537.         beq.b    .Exit
  538.  
  539. ; let's fill the buffer
  540.  
  541.         move.l    xfdbi_SourceBuffer(a5),a0
  542.         move.l    xfdbi_TargetBuffer(a5),a1
  543.         bsr    D_SwitchAlt
  544.  
  545. ; successful exit
  546.  
  547.         moveq    #1,d0
  548. .Exit        movem.l    (a7)+,d2-d7/a2-a6
  549.         rts
  550.  
  551.     END
  552.